package com.xuelongjiang.mqdemo.mq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author xuelongjiang
 */
@Configuration
public class RabbitTopicConfig {

    private final static Logger LOGGER = LoggerFactory.getLogger(RabbitTopicConfig.class);

    @Value("${mq.queues.order.name}")
    private String orderQueue;


    @Value("${mq.topic.order.name}")
    private String orderTopic;


    @Value("${mq.queues.order.key.name}")
    private String bindKey;

    @Bean("order")
    public Queue orderQueue(){
        LOGGER.info(orderQueue);
        return new Queue(orderQueue);
    }

    @Bean("orderTopic")
    public TopicExchange orderTopic(){
        LOGGER.info(orderTopic);
        return new TopicExchange(orderTopic);
    }



    @Bean
    Binding bindingOrderExchageMessage(@Qualifier("order") Queue queue, @Qualifier("orderTopic") TopicExchange exchange ){

        LOGGER.info(orderQueue);
        LOGGER.info(bindKey);
        return BindingBuilder.bind(queue).to(exchange).with(bindKey);
    }



}
